/* 
 * File:   IntArray.cpp
 * Author: chris
 *
 * Created on February 5, 2009, 6:55 PM
 */

#include <arpa/inet.h>
#include "IntArray.h"

void IntArray::SetInt(unsigned char *buffer, int intValue, int arrayIndex) {
    // Store data in blocks in host byte order (big endian).
    intValue = htonl(intValue);
    
    int byteLocation = arrayIndex*sizeof(int);
    unsigned char *addr = (unsigned char *) &intValue;

    // copy the values of the pointer into the m_buffer
    for (unsigned int i=0; i < sizeof(int); i++) {
        buffer[i+byteLocation] = addr[i];
    }
}


int IntArray::GetInt(unsigned char *buffer, int arrayIndex) {
    int byteLocation = arrayIndex*sizeof(int);
    int intValue; // extracting this from the buffer
    unsigned char *addr = (unsigned char *) &intValue;

    // copy the values of the m_buffer into the pointer
    for (unsigned int i=0; i < sizeof(int); i++) {
        addr[i] = buffer[i+byteLocation];
    }

    // Data in blocks is in network byte order (big endian). Convert
    // back to host order.
    return ntohl(intValue);
}



